package top.codedance.iotp.tools.terminal.ui;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.common.constent.Command;
import top.codedance.iotp.tools.terminal.TerminalApplication;
import top.codedance.iotp.tools.terminal.bean.IntegerItem;

import java.awt.*;
import java.awt.event.InputEvent;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author xuedianfu
 */
public class AddModbus extends javax.swing.JDialog {
    
    public ClientPluginTester cpt;
    private static volatile long i = 0;
    private DefaultTableModel tm;
    private String[] colums = new String[]{"数据"};
    private String[][] tableData = new String[][]{};
    private int rowIndex = -1;
    private ModbusAutoChecker modbusAutoChecker;

    /**
     * Creates new form AddModbus
     */
    public AddModbus(ClientPluginTester cpt, JSONObject initData) {
        super(cpt, true);
        this.cpt = cpt;
        initComponents();
        URL url = Thread.currentThread().getContextClassLoader().getResource("logo.gif");
        ImageIcon icon = new ImageIcon(url);
        setIconImage(icon.getImage());
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setLocationRelativeTo(this.cpt.getShellFrame());
        setMinimumSize(new Dimension(550, 700));
        setResizable(true);
        setTitle("代码飞舞采控系统-添加Modbus");
        
        init();
        initResultTable();
        initRequesItemtOprationMenus();
        initEditData(initData);
    }

    public ClientPluginTester getClientPluginTester(){
        return this.cpt;
    }

    private void initEditData(JSONObject initData){
        if(initData != null){
            JSONObject client = initData.getJSONObject("client");
            jtf_id.setText(client.getString("id"));
            JSONArray items = client.getJSONArray("items");
            for (int i = 0;i < items.size();i++){
                JSONObject jsonObject = items.getJSONObject(i);
                tm.addRow(new String[]{jsonObject.toJSONString()});
            }
            rowIndex = initData.getIntValue("rowIndex");
        }
    }

    private void initResultTable(){
        tm = new DefaultTableModel(tableData, colums);
        jt_result.setModel(tm);
    }

    private JPopupMenu paramHelpJpm;

    private void initRequesItemtOprationMenus() {
        paramHelpJpm = new JPopupMenu();
        JMenuItem mi_del = new JMenuItem("删除");
        mi_del.addActionListener(e -> {
            int[] selectedRows = jt_result.getSelectedRows();
            Arrays.sort(selectedRows);
            for(int i = selectedRows.length -1; i >=0; i--) {
                tm.removeRow(selectedRows[i]);
                getAutoincrement();
            }
        });
        paramHelpJpm.add(mi_del, 0);
        jt_result.add(paramHelpJpm);
    }
    
    private void init(){
        DefaultComboBoxModel<IntegerItem> cbm1 = new DefaultComboBoxModel<>();
        cbm1.addElement(new IntegerItem("读取线圈状态 (01)", 1));
        cbm1.addElement(new IntegerItem("读取输入状态 (02)", 2));
        cbm1.addElement(new IntegerItem("读取保持寄存器 (03)", 3));
        cbm1.addElement(new IntegerItem("读取输入寄存器 (04)", 4));
        cbm1.addElement(new IntegerItem("强置单线圈 (05)", 5));
        cbm1.addElement(new IntegerItem("预置单寄存器 (06)", 6));
        cbm1.addElement(new IntegerItem("读取异常状态 (07)", 7));
        cbm1.addElement(new IntegerItem("回送诊断校验 (08)", 8));
        cbm1.addElement(new IntegerItem("编程(只用于484) (09)", 9));
        cbm1.addElement(new IntegerItem("控询(只用于484) (10)", 10));
        cbm1.addElement(new IntegerItem("读取事件计数 (11)", 11));
        cbm1.addElement(new IntegerItem("读取通信事件记录 (12)", 12));
        cbm1.addElement(new IntegerItem("编程(184/384/484/584) (13)", 13));
        cbm1.addElement(new IntegerItem("探询(184/384/484/584) (14)", 14));
        cbm1.addElement(new IntegerItem("强置多线圈 (15)", 15));
        cbm1.addElement(new IntegerItem("预置多寄存器 (16)", 16));
        cbm1.addElement(new IntegerItem("报告从机标识 (17)", 17));
        cbm1.addElement(new IntegerItem("修改PC状态逻辑 (18)", 18));
        cbm1.addElement(new IntegerItem("重置通信链路 (19)", 19));
        cbm1.addElement(new IntegerItem("读取通用参数584L (20)", 20));
        cbm1.addElement(new IntegerItem("写入通用参数 (21)", 21));
        jcb_function.setModel(cbm1);
        DefaultComboBoxModel<IntegerItem> cbm2 = new DefaultComboBoxModel<>();
        cbm2.addElement(new IntegerItem("BINARY (1)", 1));
        cbm2.addElement(new IntegerItem("TWO_BYTE_INT_UNSIGNED (2)", 2));
        cbm2.addElement(new IntegerItem("TWO_BYTE_INT_SIGNED (3)", 3));
        cbm2.addElement(new IntegerItem("TWO_BYTE_INT_UNSIGNED_SWAPPED (22)", 22));
        cbm2.addElement(new IntegerItem("TWO_BYTE_INT_SIGNED_SWAPPED (23)", 23));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_INT_UNSIGNED (4)", 4));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_INT_SIGNED (5)", 5));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_INT_UNSIGNED_SWAPPED (6)", 6));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_INT_SIGNED_SWAPPED (7)", 7));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_INT_UNSIGNED_SWAPPED_SWAPPED (24)", 24));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_INT_SIGNED_SWAPPED_SWAPPED (25)", 25));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_FLOAT (8)", 8));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_FLOAT_SWAPPED (9)", 9));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_FLOAT_SWAPPED_INVERTED (21)", 21));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_INT_UNSIGNED (10)", 10));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_INT_SIGNED (11)", 11));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_INT_UNSIGNED_SWAPPED (12)", 12));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_INT_SIGNED_SWAPPED (13)", 13));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_FLOAT (14)", 14));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_FLOAT_SWAPPED (15)", 15));
        cbm2.addElement(new IntegerItem("TWO_BYTE_BCD (16)", 16));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_BCD (17)", 17));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_BCD_SWAPPED (20)", 20));
        cbm2.addElement(new IntegerItem("CHAR (18)", 18));
        cbm2.addElement(new IntegerItem("VARCHAR (19)", 19));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_MOD_10K (26)", 26));
        cbm2.addElement(new IntegerItem("SIX_BYTE_MOD_10K (27)", 27));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_MOD_10K (28)", 28));
        cbm2.addElement(new IntegerItem("FOUR_BYTE_MOD_10K_SWAPPED (29)", 29));
        cbm2.addElement(new IntegerItem("SIX_BYTE_MOD_10K_SWAPPED (30)", 30));
        cbm2.addElement(new IntegerItem("EIGHT_BYTE_MOD_10K_SWAPPED (31)", 31));
        cbm2.addElement(new IntegerItem("ONE_BYTE_INT_UNSIGNED_LOWER (32)", 32));
        cbm2.addElement(new IntegerItem("ONE_BYTE_INT_UNSIGNED_UPPER (33)", 33));
        jcb_datatype.setModel(cbm2);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtf_id = new javax.swing.JTextField();
        jtf_slaveid = new javax.swing.JTextField();
        jtf_address = new javax.swing.JTextField();
        jb_save = new javax.swing.JButton();
        jcb_function = new javax.swing.JComboBox<>();
        jcb_datatype = new javax.swing.JComboBox<>();
        jb_autoGen = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt_result = new javax.swing.JTable();
        jb_add = new javax.swing.JButton();
        jb_clean = new javax.swing.JButton();
        jb_autoCheck = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Modbus");

        jLabel2.setText("Client id：");

        jLabel3.setText("Slave id：");

        jLabel4.setText("Function：");

        jLabel5.setText("Address：");

        jLabel6.setText("Data type：");

        jtf_id.setText("0");
        jtf_id.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtf_idKeyTyped(evt);
            }
        });

        jtf_slaveid.setText("1");
        jtf_slaveid.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtf_slaveidKeyTyped(evt);
            }
        });

        jtf_address.setText("0");
        jtf_address.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtf_addressKeyTyped(evt);
            }
        });

        jb_save.setText("保存为命令");
        jb_save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_saveActionPerformed(evt);
            }
        });

        jb_autoGen.setText("自动生成");
        jb_autoGen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_autoGenActionPerformed(evt);
            }
        });

        jt_result.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jt_result.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jt_resultMousePressed(evt);
            }
        });
        jt_result.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jt_resultPropertyChange(evt);
            }
        });
        jScrollPane1.setViewportView(jt_result);

        jb_add.setText("添加");
        jb_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_addActionPerformed(evt);
            }
        });

        jb_clean.setText("清空");
        jb_clean.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_cleanActionPerformed(evt);
            }
        });

        jb_autoCheck.setText("设备自检...");
        jb_autoCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_autoCheckActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(19, 19, 19)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtf_address, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jcb_function, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jcb_datatype, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(19, 19, 19)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtf_slaveid, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                                    .addComponent(jtf_id)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jb_add)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jb_save)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jb_autoGen)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jb_clean)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jb_autoCheck)))
                        .addGap(38, 38, 38))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGap(244, 244, 244)
                .addComponent(jLabel1)
                .addContainerGap(257, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtf_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtf_slaveid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jcb_function, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jtf_address, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jcb_datatype, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jb_save)
                    .addComponent(jb_autoGen)
                    .addComponent(jb_add)
                    .addComponent(jb_clean)
                    .addComponent(jb_autoCheck))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jb_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_saveActionPerformed
        JSONObject commandParams = new JSONObject();
        commandParams.put("plugin", Command.MODBUS_COMMAND);
        JSONArray data = new JSONArray();
        for(int i = 0; i < tm.getRowCount();i++){
            data.add(JSON.parseObject((String)tm.getValueAt(i, 0)));
        }
        JSONObject clientJo = new JSONObject();
        clientJo.put("id", Integer.valueOf(jtf_id.getText()));
        clientJo.put("items", data);
        commandParams.put("client", clientJo);
        if(rowIndex < 0) {
            String defaultName = "Modbus-" + getTime();
            String name = (String) JOptionPane.showInputDialog(this, "如需重新起名，请输入新的名称。", "保存命令", JOptionPane.QUESTION_MESSAGE, null, null, defaultName);
            if (name != null && !name.isEmpty()) {
                cpt.addPluginParam(commandParams, name);
                i = 0;
                setVisible(false);
            }
        }else{
            cpt.addPluginParam(commandParams, rowIndex);
            i = 0;
            setVisible(false);
        }
    }//GEN-LAST:event_jb_saveActionPerformed

    private String getTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(new Date());
    }

    private long getAutoincrement(){
        i++;
        return i;
    }

    private void jb_autoGenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_autoGenActionPerformed
        for(int i = 33;i <= 159;i++) {
            for(int j = 0;j <= 4;j++) {
                JSONObject jo = new JSONObject();
                jo.put("tag", "tag" + getAutoincrement());
                jo.put("function", 3);
                jo.put("slaveId", i);
                jo.put("offset", 0);
                jo.put("datatype", 2);
                tm.addRow(new String[]{jo.toJSONString()});
            }
        }
    }//GEN-LAST:event_jb_autoGenActionPerformed

    private void jb_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_addActionPerformed
        JSONObject jo = new JSONObject();
        jo.put("tag", "tag" + getAutoincrement());
        jo.put("function", ((IntegerItem)jcb_function.getSelectedItem()).getValue());
        jo.put("slaveId", Integer.valueOf(jtf_slaveid.getText()));
        jo.put("offset", Integer.valueOf(jtf_address.getText()));
        jo.put("datatype", ((IntegerItem)jcb_datatype.getSelectedItem()).getValue());
        tm.addRow(new String[]{jo.toJSONString()});
    }//GEN-LAST:event_jb_addActionPerformed

    private void jt_resultMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jt_resultMousePressed
        int mods = evt.getModifiers();
        if ((mods & InputEvent.BUTTON3_MASK) != 0) {
//            if (this.getExtendedState() == Frame.MAXIMIZED_BOTH) {
//                this.paramHelpJpm.show(this, evt.getX(), evt.getYOnScreen() + this.paramHelpJpm.getHeight() / 2);
//            } else {
                this.paramHelpJpm.show(this, evt.getX(), evt.getYOnScreen() - 180);
//            }
        }
    }//GEN-LAST:event_jt_resultMousePressed

    private void jb_cleanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_cleanActionPerformed
        for(int i = jt_result.getRowCount() -1; i >=0; i--) {
            tm.removeRow(i);
        }
    }//GEN-LAST:event_jb_cleanActionPerformed

    private void jt_resultPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jt_resultPropertyChange

    }//GEN-LAST:event_jt_resultPropertyChange

    private void jb_autoCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_autoCheckActionPerformed
        if(modbusAutoChecker == null) {
            modbusAutoChecker = new ModbusAutoChecker(this);
            modbusAutoChecker.setLocationRelativeTo(this);
        }
        modbusAutoChecker.setClientId(this.jtf_id.getText());
        modbusAutoChecker.setVisible(true);
    }//GEN-LAST:event_jb_autoCheckActionPerformed

    private void jtf_idKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtf_idKeyTyped
        JTextField jtf = (JTextField)evt.getSource();
        if (!TerminalApplication.numbers.contains(evt.getKeyChar())) {
            evt.consume();
        }
        try{
            Integer.parseInt(jtf.getText());
            if(jtf.getText().startsWith("0")){
                jtf.setText(jtf.getText().replaceAll("^0+", ""));
            }
        }catch (Exception e){
            jtf.setText("0");
        }
    }//GEN-LAST:event_jtf_idKeyTyped

    private void jtf_slaveidKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtf_slaveidKeyTyped
        jtf_idKeyTyped(evt);
    }//GEN-LAST:event_jtf_slaveidKeyTyped

    private void jtf_addressKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtf_addressKeyTyped
        jtf_idKeyTyped(evt);
    }//GEN-LAST:event_jtf_addressKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jb_add;
    private javax.swing.JButton jb_autoCheck;
    private javax.swing.JButton jb_autoGen;
    private javax.swing.JButton jb_clean;
    private javax.swing.JButton jb_save;
    private javax.swing.JComboBox<IntegerItem> jcb_datatype;
    private javax.swing.JComboBox<IntegerItem> jcb_function;
    private javax.swing.JTable jt_result;
    private javax.swing.JTextField jtf_address;
    private javax.swing.JTextField jtf_id;
    private javax.swing.JTextField jtf_slaveid;
    // End of variables declaration//GEN-END:variables
}
